import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

//这是一个封装flutter_swiper的banner轮播组件
class VideoWidget extends StatefulWidget {
  var icon;
  var title;
  var source;
  var aspectRatio;
  var height;
  var isShowSpecail;

  VideoWidget({
    var icon,
    var title,
    var source,
    var aspectRatio,
    var height,
    var isShowSpecail,
  })  : this.icon = icon,
        this.title = title,
        this.source = source,
        this.aspectRatio = aspectRatio,
        this.height = height,
        this.isShowSpecail = isShowSpecail;

  @override
  State<StatefulWidget> createState() => VideoWidgetState();
}

class VideoWidgetState extends State<VideoWidget> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if (widget.isShowSpecail) {
      return new Container(
        child: new Column(
          children: <Widget>[
            //title
            specialTitle,
            Stack(children: <Widget>[
              //图片
              new Container(
                  child: new ClipRRect(
                borderRadius: BorderRadius.circular(6.0),
                child: new Image.asset(widget.icon, fit: BoxFit.fitWidth),
              )
//    new Image.network(//加载网络图片
//    'http://h.hiphotos.baidu.com/image/pic/item/21a4462309f790525fe7185100f3d7ca7acbd5e1.jpg',
                  ),
              //来源
              new Container(
                alignment: Alignment.centerLeft,
                child: new Container(
                  margin: EdgeInsets.fromLTRB(10, 10, 0, 0),
                  padding: EdgeInsets.fromLTRB(7, 4, 7, 4),
                  decoration: new BoxDecoration(
                      color: Colors.grey,
                      borderRadius: BorderRadius.all(Radius.circular(3))),
                  child: new Text(
                    "北极星招聘",
                    textAlign: TextAlign.left,
                    style: new TextStyle(color: Colors.white, fontSize: 12),
                  ),
                ),
              ),
              //播放时长
              Positioned(
                bottom: 10,
                right: 10,
                child: Container(
                  child: new Text(
                    "12：24",
                    textAlign: TextAlign.left,
                    style: new TextStyle(color: Colors.white, fontSize: 12),
                  ),
                ),
              ),
            ]),
            //title
            Container(
              margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
              alignment: Alignment.centerLeft,
              child: Text(widget.title,
                  style: new TextStyle(
                      fontWeight: FontWeight.normal, color: Colors.grey),
                  textAlign: TextAlign.left),
            )
          ],
        ),
      );
    }
    // TODO: implement build
    return new Container(
      child: new Column(
        children: <Widget>[
          //title
          Stack(children: <Widget>[
            //图片
            new Container(
                child: new ClipRRect(
              borderRadius: BorderRadius.circular(6.0),
              child: new Image.asset(widget.icon, fit: BoxFit.fitWidth),
            )
//    new Image.network(//加载网络图片
//    'http://h.hiphotos.baidu.com/image/pic/item/21a4462309f790525fe7185100f3d7ca7acbd5e1.jpg',
                ),
            //来源
            new Container(
              alignment: Alignment.centerLeft,
              child: new Container(
                margin: EdgeInsets.fromLTRB(10, 10, 0, 0),
                padding: EdgeInsets.fromLTRB(7, 4, 7, 4),
                decoration: new BoxDecoration(
                    color: Colors.grey,
                    borderRadius: BorderRadius.all(Radius.circular(3))),
                child: new Text(
                  "北极星招聘",
                  textAlign: TextAlign.left,
                  style: new TextStyle(color: Colors.white, fontSize: 12),
                ),
              ),
            ),
            //播放时长
            Positioned(
              bottom: 10,
              right: 10,
              child: Container(
                child: new Text(
                  "12：24",
                  textAlign: TextAlign.left,
                  style: new TextStyle(color: Colors.white, fontSize: 12),
                ),
              ),
            ),
          ]),
          //title
          Container(
            margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
            alignment: Alignment.centerLeft,
            child: Text(widget.title,
                style: new TextStyle(
                    fontWeight: FontWeight.normal, color: Colors.grey),
                textAlign: TextAlign.left),
          )
        ],
      ),
    );
  }

  Widget specialTitle = new Container(
    margin: EdgeInsets.fromLTRB(0, 20, 0, 20),
    child: new Row(
      //这个属性是将当前row评分，并且child是最边上
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        new Text(
          "互联网大厂养猪指南一技术贴",
          style: new TextStyle(
              fontWeight: FontWeight.bold, color: Colors.black, fontSize: 20),
          textAlign: TextAlign.left,
        ),
        new Text("更多",
            style: new TextStyle(
                fontWeight: FontWeight.normal, color: Colors.green),
            textAlign: TextAlign.right)
      ],
    ),
  );
}
